package com.jian.mall.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class CartVo {
    private List<CartItem> cartItems;
    private Integer totalCount;
    private Integer checkedCount;
    private BigDecimal totalPrice;

    public BigDecimal getTotalPrice() {
        totalPrice = new BigDecimal(0);
        if (cartItems != null && cartItems.size() > 0) {
            for (CartItem item : cartItems) {
                totalPrice = totalPrice.add(item.getTotalPrice());
            }
        }
        return totalPrice;
    }

    public Integer getCheckedCount() {
        checkedCount = 0;
        if (cartItems != null && cartItems.size() > 0) {
            for (CartItem item : cartItems) {
                if (item.getChecked()) ++checkedCount;
            }
        }
        return checkedCount;
    }

    public Integer getTotalCount() {
        return cartItems != null ? cartItems.size() : 0;
    }
}
